package com.gitee.wsl.mathematics.coordinate.ext

import com.gitee.wsl.mathematics.coordinate.d2.Coordinate2
import com.gitee.wsl.mathematics.coordinate.d3.Coordinate3
import com.gitee.wsl.mathematics.vector.ext.cross
import com.gitee.wsl.mathematics.vector.ext.dot

infix fun<T:Number> Coordinate2<T, *>.signedAngleTo(other: Coordinate2<T, *>) = angleTo(other) * sign(cross(other))
      fun<T:Number> Coordinate2<T, *>.signedAngleTo(other: Coordinate3<T, *>, axis: Coordinate3<T, *>): T = other.signedAngleTo(this, axis)

fun<T:Number> Coordinate3<T, *>.signedAngleTo(other: Coordinate2<T, *>, axis: Coordinate3<T, *>) = signedAngleTo(other.vec3, axis)
fun<T:Number> Coordinate3<T, *>.signedAngleTo(other: Coordinate3<T, *>, axis: Coordinate3<T, *>): T {
    val angle = angleTo(other)
    val crossValue = cross(other)
    val sign = sign(axis dot crossValue)
    return angle * sign
}

